package com.wy.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wy.common.R;

import com.wy.service.IAddressService;
import com.wy.entity.Address;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王昭贵
 * @since 2023-01-27
 */
@RestController
    @RequestMapping("/address")
public class AddressController {
    @Resource
    private IAddressService addressService;

    /****
     * 获取地址信息 根据地址id
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(addressService.getById(id));
    }
    /****
     * 设置默认地址
     * @param id
     * @return
     */
    @PostMapping("/setDeaultAddr")
    public R setDeafultAddr(@RequestBody int id){
        addressService.setDeafultAddr(id);
        return R.success("");
    }
    /****
     * 删除地址
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R delete(@PathVariable Integer id) {
        addressService.removeById(id);
        return R.success("");
    }
    /****
     * 新增 删除地址
     * @param address
     * @return
     */
    @PostMapping
    public R save(@RequestBody Address address) {
        addressService.saveOrUpdate(address);
        return R.success("");
    }
}

